﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Web;
using Jumbot.Common;
using Jumbot.DataOper;
namespace JumbotCms.API
{
    /// <summary>
    /// 处理CSS中标签
    /// </summary>
    public class PageCSSManage
    {
        private string m_Path = "blue912";
        private int m_BodyWidth = 1002;
        private int m_LeftWidth = 252;
        private int m_RightWidth = 740;
        private string m_TitleColor = "#00599B";
        private string m_BorderColor = "#AACCEE";
        private string m_TintBackground = "#C5E5FF";
        private string m_DarkBackground = "#316395";
        /// <summary>
        /// 皮肤路径
        /// </summary>
        public string Path
        {
            set { m_Path = value; }
            get { return m_Path; }
        }
        /// <summary>
        /// 页面主宽度
        /// </summary>
        public int BodyWidth
        {
            set { m_BodyWidth = value; }
            get { return m_BodyWidth; }
        }
        /// <summary>
        /// 左栏宽度
        /// </summary>
        public int LeftWidth
        {
            get { return m_LeftWidth; }
            set { m_LeftWidth = value; }
        }
        /// <summary>
        /// 右栏宽度
        /// </summary>
        public int RightWidth
        {
            set { m_RightWidth = value; }
            get { return m_RightWidth; }
        }
        /// <summary>
        /// 标题颜色
        /// </summary>
        public string TitleColor
        {
            set { m_TitleColor = value; }
            get { return m_TitleColor; }
        }
        /// <summary>
        /// 边框颜色
        /// </summary>
        public string BorderColor
        {
            set { m_BorderColor = value; }
            get { return m_BorderColor; }
        }
        /// <summary>
        /// 浅色背景颜色
        /// </summary>
        public string TintBackground
        {
            set { m_TintBackground = value; }
            get { return m_TintBackground; }
        }
        /// <summary>
        /// 深色背景颜色
        /// </summary>
        public string DarkBackground
        {
            set { m_DarkBackground = value; }
            get { return m_DarkBackground; }
        }

        public PageCSSManage()
        {
        }
        /// <summary>
        /// 替换css样式中的标签
        /// </summary>
        /// <param name="_cssBody"></param>
        public void Oper(ref string _cssBody)
        {
            _cssBody = _cssBody.Replace("{$SkinPath}", this.m_Path);
            _cssBody = _cssBody.Replace("{$SkinBodyWidth}", this.m_BodyWidth.ToString());
            _cssBody = _cssBody.Replace("{$SkinLeftWidth}", this.m_LeftWidth.ToString());
            _cssBody = _cssBody.Replace("{$SkinRightWidth}", this.m_RightWidth.ToString());
            _cssBody = _cssBody.Replace("{$SkinTitleColor}", this.m_TitleColor);
            _cssBody = _cssBody.Replace("{$SkinBorderColor}", this.m_BorderColor);
            _cssBody = _cssBody.Replace("{$SkinTintBackground}", this.m_TintBackground);
            _cssBody = _cssBody.Replace("{$SkinDarkBackground}", this.m_DarkBackground);
            string RegexString1 = "\\{\\$SkinBodyWidth/(?<div1>[0-9]+?)(?<join1>[\\-+]{1}?)(?<px1>[0-9]+?)\\}";
            string[] _div1 = Jumbot.Common.Strings.GetRegValue(_cssBody, RegexString1, "div1", false);
            string[] _px1 = Jumbot.Common.Strings.GetRegValue(_cssBody, RegexString1, "px1", false);
            for (int i = 0; i < _px1.Length; i++)
            {
                _cssBody = _cssBody.Replace("{$SkinBodyWidth/" + _div1[i] + "-" + _px1[i] + "}", (this.m_BodyWidth / Convert.ToInt32(_div1[i]) - Convert.ToInt32(_px1[i])).ToString());
                _cssBody = _cssBody.Replace("{$SkinBodyWidth/" + _div1[i] + "+" + _px1[i] + "}", (this.m_BodyWidth / Convert.ToInt32(_div1[i]) + Convert.ToInt32(_px1[i])).ToString());
            }
            string RegexString2 = "\\{\\$SkinLeftWidth/(?<div2>[0-9]+?)(?<join2>[\\-+]{1}?)(?<px2>[0-9]+?)\\}";
            string[] _div2 = Jumbot.Common.Strings.GetRegValue(_cssBody, RegexString2, "div2", false);
            string[] _px2 = Jumbot.Common.Strings.GetRegValue(_cssBody, RegexString2, "px2", false);
            for (int j = 0; j < _px2.Length; j++)
            {
                _cssBody = _cssBody.Replace("{$SkinLeftWidth/" + _div2[j] + "-" + _px2[j] + "}", (this.m_LeftWidth / Convert.ToInt32(_div2[j]) - Convert.ToInt32(_px2[j])).ToString());
                _cssBody = _cssBody.Replace("{$SkinLeftWidth/" + _div2[j] + "+" + _px2[j] + "}", (this.m_LeftWidth / Convert.ToInt32(_div2[j]) + Convert.ToInt32(_px2[j])).ToString());
            }
            string RegexString3 = "\\{\\$SkinRightWidth/(?<div3>[0-9]+?)(?<join3>[\\-+]{1}?)(?<px3>[0-9]+?)\\}";
            string[] _div3 = Jumbot.Common.Strings.GetRegValue(_cssBody, RegexString3, "div3", false);
            string[] _px3 = Jumbot.Common.Strings.GetRegValue(_cssBody, RegexString3, "px3", false);
            for (int k = 0; k < _px3.Length; k++)
            {
                _cssBody = _cssBody.Replace("{$SkinRightWidth/" + _div3[k] + "-" + _px3[k] + "}", (this.m_RightWidth / Convert.ToInt32(_div3[k]) - Convert.ToInt32(_px3[k])).ToString());
                _cssBody = _cssBody.Replace("{$SkinRightWidth/" + _div3[k] + "+" + _px3[k] + "}", (this.m_RightWidth / Convert.ToInt32(_div3[k]) + Convert.ToInt32(_px3[k])).ToString());
            }
        }
    }
}
